#pragma once

#include <iostream>
#include"Log.h"
using namespace std;

char operates[] = {'+', '-', '*', '/', '%', '&',  '~', '|', '!', '^'};
class task
{
public:
    task() {} // 需要一个默认的构造函数
    task(int x, int y, char operat)
        : _x(x), _y(y), _operat(operat)
    {
        l.enable(0);//日志在显示器打印
    }

    void operator()()
    {
        switch (_operat)
        {
        case '+':
            _result = _x + _y;
            break;
        case '-':
            _result = _x - _y;
            break;
        case '*':
            _result = _x * _y;
            break;
        case '/':
        {
            if (_y == 0)
            {
                _s = "除数为0";
            }
            else
                _result = _x / _y;
        }
        break;
        case '&':
            _result = _x & _y;
            break;
        case '|':
            _result = _x | _y;
            break;
        case '^':
            _result = _x ^ _y;
            break;
        default:
            _s = "目前未录入该操作";
            break;
        }
    }
    void print_task_finish()
    {
        if (_s.empty())
            cout << _x << _operat << _y << " = " << _result ;
        else
            cout << _s ;

        l.Log_infom(Info,"  ");
        
    }
    void print_task_start()
    {
        cout << _x << _operat << _y << " = ???";
        l.Log_infom(Info,"  ");
    }
    ~task()
    {
    }

private:
    int _x;
    int _y;
    int _result;
    string _s; // 存放错误信息
    char _operat;
};